package com.qf.kdgroup.gdbackend.controller;

import com.github.pagehelper.PageInfo;
import com.qf.kdgroup.gdbackend.dto.ResultBean;
import com.qf.kdgroup.gdbackend.entity.Device;
import com.qf.kdgroup.gdbackend.service.DeviceService;
import com.qf.kdgroup.gdbackend.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/device")
@CrossOrigin
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/getList")
    @ResponseBody
    public PageInfo getList(@RequestBody PageVO pageVO){
        PageInfo pageInfo = deviceService.getDevicesList(pageVO);
        return pageInfo;
    }

    @PostMapping("/add")
    @ResponseBody
    public ResultBean add(@RequestBody Device device){
        return deviceService.addDevice(device);
    }

    @PostMapping("/find")
    @ResponseBody
    public Device find(@RequestBody Device device){
        return deviceService.getDevice(device.getDid());
    }

    @PostMapping("/update")
    @ResponseBody
    public ResultBean update(@RequestBody Device device){
        return deviceService.updateDevice(device);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public ResultBean delete(@RequestBody Device device){
        return deviceService.deleteDevice(device.getDid());
    }

}
